package com.learn.micro_mall.repository.brand;

import com.learn.micro_mall.dao.brand.BrandMapper;
import com.learn.micro_mall.dao.brand.model.Brand;
import com.learn.micro_mall.domain.entity.brand.BrandEntity;
import com.learn.micro_mall.repository.convertor.brand.BrandConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class BrandRepository {

    @Resource
    private BrandMapper brandMapper;

    public BrandEntity getBrandEntityByBrandName(String brandName){
        Brand brand = brandMapper.getByBrandName(brandName);
        return BrandConvert.INSTANCES.toBrandEntity(brand);
    }

    /**
     * 新增品牌信息
     * @param brandEntity
     * @return
     */
    public boolean insertBrandEntity(BrandEntity brandEntity) {
        Brand brand = BrandConvert.INSTANCES.toBrand(brandEntity);
        brandMapper.insert(brand);
        return true;
    }

    /**
     * 更新品牌信息
     * @param brandEntity
     * @return
     */
    public boolean updateBrandEntity(BrandEntity brandEntity){
        Brand brand = BrandConvert.INSTANCES.toBrand(brandEntity);
        brandMapper.updateByBrandName(brand);
        return true;
    }

    /**
     * 删除品牌信息
     * @param brandEntity
     * @return
     */
    public boolean deleteBrandEntity(BrandEntity brandEntity){
        brandMapper.deleteByBrandName(brandEntity.getBrandId().getBrandName());
        return true;
    }
}
